﻿$(function () {
    menuActive("admin");
    $("#StatusV").after('<span class="lbl"></span>');
});

$("#adminForm").submit(function () {
    $(this).ajaxSubmit({
        dataType:"json",
        beforeSubmit:function() {
          if (!$("#Account").val()) {
              layer.msg("请填写管理员账号！", { icon: 2 });
              return false;
          }
          if (!$("#Password").val()) {
              layer.msg("请填写管理员密码！", { icon: 2 });
              return false;
          }
          layer.load();
          return true;
        },
        success: function (res, status) {
            switch (res.code) {
                case "N200":
                    layer.closeAll('loading');
                    layer.msg(res.msg, { icon: 1 });
                    setTimeout(function () {
                        window.location.href = res.returnurl;
                    }, 2000);
                    break;
                default:
                    layer.closeAll('loading');
                    layer.msg(res.msg, { icon: 2 });
                    break;
            }
        }
    });
    return false;
});

function Delete(itemid) {
    layer.confirm("确认删除这名管理员？此操作不可逆！", function () {
        var loading = layer.load();
        simpleAjax("/admin/del/" + itemid, "json", null, function(res) {
            switch (res.code) {
            case "N200":
                layer.close(loading);
                layer.msg(res.msg, { icon: 1 });
                setTimeout(function() {
                    window.location.href = res.returnurl;
                }, 2000);
                break;
            default:
                layer.close(loading);
                layer.msg(res.msg, { icon: 2 });
                break;
            }
        });
    });
}